import 'package:flutter/material.dart';
import 'package:top_foundation/component/wrap.dart';
import 'package:top_foundation/utils/ex/color.dart';
import 'package:top_foundation/utils/util.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class GridPage extends GetView<GridController> {
  const GridPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    return ListView(
      children: [
        Container(
          height: 307.r,
          margin: EdgeInsets.only(top: 18.r),
          padding: EdgeInsets.fromLTRB(24.r, 15.r, 24.r, 19.r),
          color: Colors.amber,
          child: LayoutBuilder(builder: (context, cons) {
            var spacing = (cons.biggest.width - (51.r * 6)) / 5;
            var runSpacing = (cons.biggest.height - (51.r * 5)) / 4;
            return RaidersGridView(
              spacing: spacing,
              runSpacing: spacing,
              centerChild: Container(
                color: ColorEx.random,
                alignment: Alignment.center,
                child: Text(
                  '000',
                  style: TextStyle(color: Colors.white),
                ),
              ),
              itemBuilder: (index) {
                return Container(
                  color: ColorEx.random,
                  alignment: Alignment.center,
                  child: Text(
                    '$index',
                    style: TextStyle(color: Colors.white),
                  ),
                );
              },
            );
          }),
        ),
        SizedBox(height: 30),
        IWrap(
          itemBuilder: (context, index) {
            return Container(
              color: ColorEx.random,
              height: 40.r,
              alignment: Alignment.center,
              child: Text('$index'),
            );
          },
          column: 5,
          spacing: 10,
          runSpacing: 10,
        ),
        SizedBox(height: 30),
        DashLine(),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<GridController>(
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("grid")),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
